//
//  MBProgressHUD+Utility.m
//  DemoMBProgressHUD
//
//  Created by 唐可雄 on 16/9/28.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "MBProgressHUD+Utility.h"

@implementation MBProgressHUD (Utility)

+ (void)showToast:(NSString *)str {
    [self showToast:str inView:[UIApplication sharedApplication].keyWindow];
}

+ (void)showToast:(NSString *)str inView:(UIView *)view {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    hud.label.text = str;
    hud.label.numberOfLines = 0;
    [hud hideAnimated:NO afterDelay:(str.length < 10 ? 1 : str.length/10)];
}

+ (void)showToast:(NSString *)str icon:(UIImage *)icon {
    [self showToast:str icon:icon inView:[UIApplication sharedApplication].keyWindow];
}

+ (void)showToast:(NSString *)str icon:(UIImage *)icon inView:(UIView *)view {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    hud.customView = [[UIImageView alloc] initWithImage:icon];
    hud.label.text = str;
    hud.label.numberOfLines = 0;
    [hud hideAnimated:NO afterDelay:(str.length < 10 ? 1 : str.length/10)];
}

@end
